<?php
namespace model;

abstract class Base{
    use \dk\traits\Singleton;
    
    protected $table;

    public function __construct(){
        $this->table = $this->getTable();
    }

    protected static $tableInstance;
    abstract public function getTable();
    
    public function update($post, $where, $mask = 1){
        return $this->table->update($post, $where, $mask);
    }
    public function replace($post, $where, $mask = 1){
        return $this->table->replace($post, $where, $mask);
    }
    /**
     * @param array $where
     * @return \sp\db\mysql\ResultSet
     */
    public function find(array $where = array()){
        return $this->table->select($where);
    }
    /**
     * @param array $where
     */
    public function delete(array $where){
        return $this->table->delete($where);
    }

    public function count(array $where = array()){
        return $this->table->count($where);
    }

    public function getInfo($where){
        if(is_numeric($where)){
            $where = array('id' => $where);
        }
        $where['_limit'] = 1;
        return $this->find($where)->current();
    }
}
